import { Base64 } from 'js-base64';

const parseJwt = (token) => {
  if (!token) {
    return null;
  }
  const jwtSplit = token.split('.');
  if (jwtSplit.length !== 3) {
    return null;
  }
  const payload = jwtSplit[1];
  const buffer = Base64.decode(payload);
  return JSON.parse(buffer);
};

export default parseJwt;
